<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <link rel="stylesheet" href="../../css/print.css"/>
    <style>

    </style>
</head>
<body class="print-wrap">
<button id="print-btn" class="layui-btn layui-btn-xs ares-d-print-none ares-position-absolute ares-absolute-tr-offset">打印</button>
<h3>基本信息</h3>
<div class="ares-mb emr-info"></div>
<h3>治疗记录 <span id="item-type-name"></span></h3>
<table class="layui-hide" id="table" lay-filter="table"></table>
<div id="pagination"></div>


<script type="text/javascript" src="../../plugins/html2canvas.min.js"></script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var init;
    layui.use(['table', 'conf', 'laypage', 'dateFilters', 'commonServices', 'mandyServices', 'qs', 'printArea'], function (table, config, laypage, dateFilters, commonServices, mandyServices, qs, printArea) {
        var emrId, isReferralHistory, itemType, itemId;

        var trainStatusDescribe = ["未处理训练状态", "已进行训练", "已取消训练"],
            summaryStatusDescribe = ["未处理小结状态", "已小结", "已取消小结"],
            statusDescribe = [trainStatusDescribe, summaryStatusDescribe];

        init = function () {
            var localHash = location.hash,
                queryStr = localHash.split('?')[1],
                routerParams = top.layui.routers.params,
                routerQuery = queryStr ? qs.parse(queryStr) : {};
            console.log(localHash, queryStr, routerParams, routerQuery)
            emrId = routerParams.emrId;
            isReferralHistory = routerQuery.isReferralHistory;
            itemType = window.decodeURIComponent(routerQuery.itemType);
            itemId = routerQuery.itemId;
            $('#item-type-name').text('(' + itemType + ')');
            getPatientInfo()
            getPageList(1, 1000);
        }

        init();
        /**
         * @author: ares
         * @date: 2021/3/30 11:51
         * @description: 打印
         */
        $('#print-btn').on('click', function () {
            html2canvas($('#table').next()[0]).then(canvas => {
                $('.print-img').remove();
                var dataUrl = canvas.toDataURL();
                $('#table').before('<img class="print-img ares-d-print-block" src="'+dataUrl+'"/>');
                $('.print-wrap').printArea();
            });

        })

        /**
         * @author: ares
         * @date: 2021/3/30 12:42
         * @description: 分页查询
         * @param{number} page
         * @param{number} pageSize
         */
        function getPageList(page, pageSize) {
            var params = {
                emr_id: emrId,
                is_referral_history: isReferralHistory,
                item_type: itemType,
                item_id: itemId,
            };
            mandyServices.mandy_get_treatment_record_list(page, pageSize, params).then(function (res) {
                var data = res.data;
                /*laypage.render($.extend(config.pagination, {
                    count: data.count,
                    curr: data.current_page,
                    jump: function (obj, first) {
                        if (!first) getPageList(obj.curr, obj.limit);
                    }
                }));*/
                table.render({
                    elem: '#table',
                    data: data.list,
                    cellMinWidth: 80,
                    cols: [[
                        {title: '治疗总次数', width: 100, templet: '<span>{{d.prescription_item.times}}</span>'},
                        {title: '未完成次数', width: 100, field: 'current_item_residue_times'},
                        {title: '治疗师', width: 100, templet: '<span>{{d.therapist.name}}</span>'},
                        {
                            title: '状态',
                            width: 120,
                            templet: function (d) {
                                return statusDescribe[d.type][d.status];
                            }
                        },
                        {
                            title: '完成时间', width: 150,
                            templet: function (d) {
                                return dateFilters.dateTimeFormat(d.finish_time);
                            }
                        },
                        {title: '情况描述', field: 'condition'},
                    ]]
                });
            });
        }

        /**
         * @author: ares
         * @date: 2021/3/10 10:49
         * @description: 获取患者基本信息
         */
        function getPatientInfo() {
            commonServices.getEmrInfoService(emrId, null, null, $('.emr-info'))
        }
    })
</script>
</body>
</html>
